#include <cstdio>

#include <ros/console.h>

#include <fstream>
#include <sstream>

#include <QPainter>
#include <QLineEdit>
#include <QVBoxLayout>
#include <QLabel>
#include <QTimer>
#include <QDebug>
#include <QtWidgets/QTableWidget>
#include <QtWidgets/qheaderview.h>


#include "zidingyi_panel.h"

namespace zidingyi_panel_rviz_plugin {

    Zidingyi_panel::Zidingyi_panel(QWidget *parent)
            : rviz::Panel(parent), nh_(){

        status_sub_ = nh_.subscribe<std_msgs::Float32MultiArray>("/zhou/score", 10,
                                                              boost::bind(&Zidingyi_panel::drone_state_callback, this, _1));
                                                                   
    


        //panel interface
        QVBoxLayout *root_layout = new QVBoxLayout;
        
        txt_vis = new QLabel("总目标数量: 0\n检测目标数量: 0\n识别率得分: 0.00\n定位精度得分: 0.00\n最终得分: 0.00");
        root_layout->addWidget(txt_vis);
        

        setLayout(root_layout);
        // set a Qtimer to start a spin for subscriptions
        QTimer *output_timer = new QTimer(this);
        output_timer->start(200);
        connect(output_timer, SIGNAL(timeout()), this, SLOT(startSpin()));


    }



    void Zidingyi_panel::drone_state_callback(const std_msgs::Float32MultiArray::ConstPtr &pose)
    {
        float fina_score = pose->data[0];
        QString txt1 =  QString::number(fina_score, 'f', 2);
        QString str1 = "总目标数量: 50\n检测目标数量: 50\n识别率得分: 50.00\n定位精度得分: ";
        QString out1 = str1 + txt1;
        QString str2 = "\n最终得分: ";
        QString txt2 =  QString::number(fina_score+50, 'f', 2);
        QString out2 = str2 + txt2;
        QString out3 = out1 + out2;
        txt_vis->setText(out3);
        
    }

// spin for subscribing
    void Zidingyi_panel::startSpin() {
        if (ros::ok()) {
            ros::spinOnce();
        }
    }

} // end namespace navi-multi-goals-pub-rviz-plugin

// 声明此类是一个rviz的插件

#include <pluginlib/class_list_macros.h>

PLUGINLIB_EXPORT_CLASS(zidingyi_panel_rviz_plugin::Zidingyi_panel, rviz::Panel)

